package com.mallcloud.mall.mall.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallVipRightsModel;
import com.mallcloud.mall.mall.service.MallVipRightsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-会员权益")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/vipRights")
public class MallVipRightsController {
	private final MallVipRightsService vipRightsService;

	@ApiOperation("分页")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('mall_viprights_view')")
	public R page(Page page, MallVipRightsModel vipRightsModel) {
		return R.ok(vipRightsService.page(page, Wrappers.query(vipRightsModel)));
	}

	@ApiOperation("查询详情")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('mall_viprights_view')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(vipRightsService.getById(id));
	}

	@ApiOperation("新增")
	@PostMapping("/save")
	@PreAuthorize("@pms.hasPermission('mall_viprights_add')")
	public R save(@RequestBody MallVipRightsModel vipRightsModel) {
		return R.ok(vipRightsService.save(vipRightsModel));
	}

	@ApiOperation("修改")
	@PostMapping("/update")
	@PreAuthorize("@pms.hasPermission('mall_viprights_edit')")
	public R updateById(@RequestBody MallVipRightsModel vipRightsModel) {
		return R.ok(vipRightsService.updateById(vipRightsModel));
	}

	@ApiOperation("删除")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('mall_viprights_del')")
	public R removeById(@PathVariable String id) {
		return R.ok(vipRightsService.removeById(id));
	}

	@ApiOperation("批量删除")
	@DeleteMapping
	@PreAuthorize("@pms.hasPermission('mall_viprights_del')")
	public R removeByIds(@RequestBody String[] ids) {
		return R.ok(vipRightsService.removeBatchByIds(CollUtil.toList(ids)));
	}

	@ApiOperation("导出")
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('mall_viprights_export')")
	public List<MallVipRightsModel> export(MallVipRightsModel vipRightsModel) {
		return vipRightsService.list(Wrappers.query(vipRightsModel));
	}
}
